home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 3718 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: doc.ic.ac.uk!not-for-mail
  2. From: mdf@doc.ic.ac.uk (Martin Frost)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: ..
  5. Date: 23 Feb 1996 16:37:19 -0000
  6. Organization: Dept. of Computing, Imperial College, University of London, UK.
  7. Distribution: world
  8. Message-ID: <4gkqfv$i7c@oak44.doc.ic.ac.uk>
  9. References: <0099DD37.C8BBBFBC@netins.net> <4g9g78$eri@btmpjg.god.bel.alcatel.be>
  10. Reply-To: mdf@doc.ic.ac.uk (Martin Frost)
  11. NNTP-Posting-Host: oak44.doc.ic.ac.uk
  12. X-Newsreader: mxrn 6.18-23
  13.  
  14.  
  15. In article <4g9g78$eri@btmpjg.god.bel.alcatel.be>, barnhoorn@nlev00 () writes:
  16. >In article <0099DD37.C8BBBFBC@netins.net>, tempest@netins.net writes:
  17. >|> If I wanted to make a progress bar for like loading a file.. showing
  18. >|> the bar slowely moving across the box (filling up the percentage done).
  19. >|> and perhaps print the percentage in the middle of this box, how would
  20. >|> I go about doing it?   Any one have some example code or info on how
  21. >|> I could do it.. thanks.. 
  22.  
  23. [code showing how to draw the bar deleted]
  24.  
  25. You need to combine this bar code with splitting up your read into blocks,
  26. and update the bar after each read, as there is no way to determine how
  27. far the read has got otherwise.
  28.  
  29. like this:
  30.  
  31. #define EACH_READ_LEN 50000
  32. #define LAST_READ_LEN 70000
  33.  
  34. /* return value same as Read() */
  35. LONG ProgressRead(BPTR File, APTR Buffer, ULONG Length)
  36.   {
  37.   ULONG Progress;
  38.   LONG NumRead;
  39.   DrawBar(0, Length);    /* draw empty bar */
  40.  
  41.   Progress = 0;
  42.   do
  43.     {
  44.     NumRead = Read(File, Buffer, EACH_READ_LEN);
  45.     if(ReadVal < 0) return(-1);        /* error */
  46.     Progress += ReadVal;
  47.     DrawBar(Progress,Length);
  48.     }
  49.     while(ReadVal > 0);
  50.  
  51.   return(Progress);
  52.   }
  53.  
  54. This assumes a routine DrawBar(curr, max) which draws a bar for curr bytes
  55. completed out of max.
  56.  
  57. Martin
  58.